//
//  RepairDetailController.m
//  智慧小区
//
//  Created by lab603 on 15/6/30.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "RepairDetailController.h"
#import "RepairDetailView.h"
#import "PPDownLoadTool.h"
#import "Repair.h"
#import "MJAudioTool.h"
@interface RepairDetailController ()
@property (nonatomic,weak) RepairDetailView *detailView;
//语音文件名
@property (nonatomic,copy) NSString *fileName;
@end

@implementation RepairDetailController
- (id)init{
    if (self=[super init]) {
        self.title = @"报修详情";
        self.view.backgroundColor = APP_BACK_COLOR;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
}
/**
 *  初始化scrollView
 */
- (void)initScrollView{
    RepairDetailView *detailView = [[RepairDetailView alloc] init];
    detailView.repair = self.repair;
    detailView.frame = CGRectMake(0, 0, ScreenWidth, detailView.viewHeight);
    [detailView setTapVoiceBtnBlock:^{
        [MJAudioTool playMusic:self.fileName];
    }];
    self.detailView = detailView;
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds;
    scrollView.contentSize = self.detailView.frame.size;
    [scrollView addSubview:self.detailView];
    [self.view addSubview:scrollView];
}
- (void)setRepair:(Repair *)repair{
    _repair = repair;
    //详情里若有语音文件，则下载
    if (repair.voice) {
       [self downLoadVoiceFile];
    }
    //初始化scrollView
    [self initScrollView];
    
}
/**
 *  下载语音文件
 */
- (void)downLoadVoiceFile{
    NSString *voiceString = [NSString stringWithFormat:@"%@%@",StaticFileUrl,self.repair.voice];
    PPDownLoadTool *downLoadTool = [[PPDownLoadTool alloc] init];
    [downLoadTool startDownload:voiceString];
    self.fileName = downLoadTool.cacheFile;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
